<template>
  <j-modal title="退诊信息填写" :width="900" :visible="visible" :confirmLoading="loading" switchFullscreen
    @cancel="handleCancel" @ok="handleOk">
    <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol"
      style="padding:0 0 20px 20px;">
      <a-row>
        <a-col :span="12">
          <a-form-model-item label="病人编号" prop="patientId">
            <a-input v-model="form.patientId" :disabled="isDisabled" placeholder="请输入"> </a-input>
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="入组时间" prop="groupTime">
            <a-date-picker allowClear v-model="form.groupTime"  disabled valueFormat="YYYY-MM-DD" style="width:100%" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="12">
          <a-form-model-item label="退出时间" prop="quitTime">
            <a-date-picker allowClear v-model="form.quitTime" valueFormat="YYYY-MM-DD" style="width:100%" />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="退出原因" prop="quitReason">
            <a-select v-model="form.quitReason" placeholder="请选择">
              <a-select-option v-for="(item, key) in reasonArr" :key="key" :value="item.value">{{ item.title }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="12">
          <a-form-model-item label="填表日期" prop="fillFormTime">
            <a-date-picker allowClear v-model="form.fillFormTime" valueFormat="YYYY-MM-DD" style="width:100%" />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label=" 医生编号" prop="doctorId">
            <a-input v-model="form.doctorId" placeholder="请输入"> </a-input>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </j-modal>
</template>
<script>
import * as treatApi from '@/api/sjsk/help/treat.js'
import { getDictItemsFromCache } from '@/api/api'
export default {
  components: {},
  data() {
    return {
      labelCol: { span: 22 },
      wrapperCol: { span: 22 },
      reasonArr: getDictItemsFromCache('quitClinicReason'),
      form: {},
      rules: {
        patientId: [{ required: true, message: '请输入' }],
        groupTime: [{ required: true, message: '请选择' }],
        quitTime: [{ required: true, message: '请选择' }],
        quitReason: [{ required: true, message: '请选择' }],
        fillFormTime: [{ required: true, message: '请选择' },],
        doctorId: [{ required: true, message: '请输入' }]
      },
      visible: false,
      loading: false,
      isDisabled: true,
    }
  },
  created() {
    // let user = Vue.ls.get(USER_INFO)
    // this.form.apprehendUser = Vue.ls.get(USER_INFO).realname
  },
  methods: {
    show(record) {
      this.visible = true
      this.$set(this.form, 'patientId', record.patientId)
      this.$set(this.form, 'groupTime', record.groupTime)
      this.$set(this.form, 'clinicRegion', record.clinicRegion)
      this.$set(this.form, 'regionWords', record.regionWords)
      this.$set(this.form, 'clinicName', record.clinicName)
    },
    rangePickerChange(date) {
      // this.$set(this.form, 'startTime', date[0])
      // this.$set(this.form, 'endTime', date[1])
    },
    handleCancel() {
      this.visible = false
    },
    handleOk() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.loading = true
          treatApi.addWithdrawalByPid(this.form).then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.$emit('ok');
              this.visible = false
              this.loading = false
            } else {
              this.loading = false
              this.$message.warn(res.message)
            }
          })
            .catch(e => {
              this.loading = false
              this.$message.warn('请求失败！')
            })
        }
      })
    }
  }
}
</script>
<style scoped lang="less">
/deep/.ant-col-22 {
  text-align: left;
}

/deep/.ant-row {
  margin-bottom: 0;
}
</style>
